package com.mck.mapper;

import com.mck.entity.ScoreStats;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ScoreStatsMapper {

    /**
     * 获取成绩统计数据
     */
    // @Select("select * from score_stats where academyYear = #{academyYear} and  class_id = #{classId} and  subject_id = #{subjectId}")
    List<ScoreStats> getScoreStatsList(ScoreStats scoreStats);

    /**
     * 添加成绩统计数据
     */
    @Insert("""
                INSERT INTO subject_score_stats (
                    academy_year,
                    class_id,
                    subject_id,
                    excellent_rate_theory,
                    pass_rate_theory,
                    avg_score_theory,
                    max_score_theory,
                    update_time_theory,
                    excellent_rate_practice,
                    pass_rate_practice,
                    avg_score_practice,
                    max_score_practice,
                    update_time_practice,
                    theory_total_violations,
                    theory_total_absences,
                    theory_violation_student_ids,
                    top_theory_student_ids,
                    practice_total_violations,
                    practice_total_absences,
                    practice_violation_student_ids,
                    top_practice_student_ids
                )
                VALUES (
                    #{academyYear},
                    #{classId},
                    #{subjectId},
                    #{excellentRateTheory},
                    #{passRateTheory},
                    #{avgScoreTheory},
                    #{maxScoreTheory},
                    #{updateTimeTheory},
                    #{excellentRatePractice},
                    #{passRatePractice},
                    #{avgScorePractice},
                    #{maxScorePractice},
                    #{updateTimePractice},
                    #{theoryTotalViolations},
                    #{theoryTotalAbsences},
                    #{theoryViolationStudentIds},
                    #{topTheoryStudentIds},
                    #{practiceTotalViolations},
                    #{practiceTotalAbsences},
                    #{practiceViolationStudentIds},
                    #{topPracticeStudentIds}
                )
            """)
    void addScoreStats(ScoreStats scoreStats);

    /**
     * 更新成绩统计数据
     */
    @Update("""
                update subject_score_stats set
                    excellent_rate_theory = #{excellentRateTheory},
                    pass_rate_theory = #{passRateTheory},
                    avg_score_theory = #{avgScoreTheory},
                    max_score_theory = #{maxScoreTheory},
                    update_time_theory = #{updateTimeTheory},
                    excellent_rate_practice = #{excellentRatePractice},
                    pass_rate_practice = #{passRatePractice},
                    avg_score_practice = #{avgScorePractice},
                    max_score_practice = #{maxScorePractice},
                    update_time_practice = #{updateTimePractice},
                    theory_total_violations = #{theoryTotalViolations},
                    theory_total_absences = #{theoryTotalAbsences},
                    theory_violation_student_ids = #{theoryViolationStudentIds},
                    top_theory_student_ids = #{topTheoryStudentIds},
                    practice_total_violations = #{practiceTotalViolations},
                    practice_total_absences = #{practiceTotalAbsences},
                    practice_violation_student_ids = #{practiceViolationStudentIds},
                    top_practice_student_ids = #{topPracticeStudentIds}
                where class_id = #{classId}
                    and subject_id = #{subjectId}
                    and academy_year = #{academyYear}
            """)
    void updateScoreStats(ScoreStats scoreStats);
}
